package com.ljsw.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.ljsw.activity.R;

/**
 * 单人指纹验证 Dialog 作者: 石锚 版本: 1.0 日期: 2015-10-15
 */
public class OneFingerDialog  {
	public OneFingerDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();// 获取屏幕分辨率
	}

	
	private Context context;
	private Display display;
	private Dialog dialog;
	private LinearLayout layout_finger;
	private TextView finger_title, finger_name, finger_tishi;
	private ImageView finger_image;// 指纹图片
	
	public OneFingerDialog builder(){
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_finger_check_one, null);
		layout_finger = (LinearLayout) view.findViewById(R.id.layout_finger_one);
		finger_title = (TextView) view.findViewById(R.id.finger_top);
		finger_name =  (TextView) view.findViewById(R.id.yayunyuan_name);	
		finger_image = (ImageView) view.findViewById(R.id.finger_image);
		finger_tishi =  (TextView) view.findViewById(R.id.finger_btm);
		// 添加Dialog样式
		dialog = new Dialog(context, R.style.FingerDialog);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域不关闭Dialog	
		// 调整dialog背景大小
		layout_finger.setLayoutParams(new FrameLayout.LayoutParams((int) (display
				.getWidth() * 0.7), LayoutParams.WRAP_CONTENT));
		return this;
	}

	/**
	 * 设置标题
	 * 
	 * @param title
	 * @return
	 */
	public OneFingerDialog setTitle(String title) {
		finger_title.setText(title);
		return this;
	}
	
	/**
	 * 设置标题
	 * 
	 * @param title
	 * @return
	 */
	public OneFingerDialog setBottom(String bottom) {
		finger_tishi.setText(bottom);
		return this;
	}

	/**
	 * 设置人名
	 * 
	 * @param title
	 * @return
	 */
	public OneFingerDialog setName(String name) {
		finger_name.setText(name);
		return this;
	}
	/**
	 * 设置指纹
	 * 
	 * @param title
	 * @return
	 */
	public OneFingerDialog setFingerImage(Bitmap map) {
		finger_image.setImageBitmap(map);
		return this;
	}

	/**
	 * 点击事件
	 * 
	 * @param text
	 * @param listener
	 * @return
	 */
	public OneFingerDialog setQueDing(final OnClickListener listener) {
		layout_finger.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}

	public void show() {
		dialog.show();
		
	}

	public void dismiss() {
		dialog.dismiss();
	}
	
	public void setImageBitmap(Bitmap bitmap){
		finger_image.setImageBitmap(bitmap);
	}
	
	public boolean isshow(){
		return dialog.isShowing();
	}
}
